﻿<UserControl x:Class="Southridge.View.SearchCriteriaView"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:dg="http://schemas.microsoft.com/wpf/2008/toolkit" 
    xmlns:view="clr-namespace:Southridge.View"
    xmlns:biz="clr-namespace:Southridge.Business;assembly=Southridge.Business"
    xmlns:controls="clr-namespace:Southridge.Controls;assembly=Southridge.Controls"
    xmlns:sys="clr-namespace:System;assembly=mscorlib"
             >
    
    <UserControl.Resources>

        <!--MAB CHANGE-->
        <view:ListingToOneLineAddressConverter x:Key="ListingToOneLineAddressConverter" />
        <!--MAB CHANGE-->
        <view:BoolToVisibilityConverter x:Key="BoolToVisibilityConverter" />

    </UserControl.Resources>
    <Grid>
        <dg:DataGrid
      Name="dg1"            
      ItemsSource="{Binding Results}" 
      Background="White"
      AlternatingRowBackground="#103D7EC5"       
      RowHeaderWidth="20" 
      AutoGenerateColumns="false" 
      SelectionMode="Extended"  
      SelectionUnit="FullRow" 
      GridLinesVisibility="None"        
      EnableRowVirtualization="False"
      EnableColumnVirtualization="False"       
      CanUserSortColumns="True"
      CanUserAddRows="False"                 
      RowDetailsVisibilityMode="VisibleWhenSelected">
            <dg:DataGrid.Resources>
                <view:DataContextSpy x:Key="spy" />

            </dg:DataGrid.Resources>
            <dg:DataGrid.RowDetailsTemplate>
                <DataTemplate>
                    <StackPanel Orientation="Horizontal" Margin="30,5,5,5" HorizontalAlignment="Left">
                        <TextBlock Text="{Binding Description}"  MaxWidth="800" TextTrimming="WordEllipsis"/>
                        <Button Content="More..." Height="20" FontSize="10" Margin="5,0,0,0"
                                    Command="{Binding Source={StaticResource spy}, Path=DataContext.ShowDetails}" CommandParameter="{Binding}"/>
                    </StackPanel>
                </DataTemplate>
            </dg:DataGrid.RowDetailsTemplate>

            <dg:DataGrid.RowValidationRules>
                <biz:SampleListingValidationRule ValidationStep="ConvertedProposedValue"/>
            </dg:DataGrid.RowValidationRules>
            <dg:DataGrid.RowValidationErrorTemplate>
                <ControlTemplate>
                    <Grid VerticalAlignment="Center" Margin="1,0,0,0" Background="Red">
                        <Grid.ToolTip>
                            <ToolTip Content="Date Updated may not be before Date Listed."/>
                        </Grid.ToolTip>
                        <Path HorizontalAlignment="Left" VerticalAlignment="Top" Width="16.575" Height="15.013" Fill="#FFFF0000" Stretch="Fill" Data="M2.1923326,13.126918 C2.1923326,13.126918 9.1242888,3.5218058 11.44987,4.1032011 13.775452,4.6845965 11.006801,6.2345933 11.006801,6.2345933 L2.7678984,12.676864 z" Margin="0,1.221,0,0"/>
                        <Path HorizontalAlignment="Left" VerticalAlignment="Top" Width="12.077" Height="14.755" Fill="#FFFF0000" Stretch="Fill" Data="M4.5860118,1.5306513 C4.1381923,2.7258072 11.531427,12.355297 15.344682,14.995039 17.329125,16.368778 11.249546,6.4430705 10.861957,6.4430705 10.474368,6.4430705 5.1923887,-0.087668306 4.5860118,1.5306513 z" Margin="2.832,1.183,0,0"/>
                        <Path HorizontalAlignment="Left" Margin="10.032,2.432,0,0" VerticalAlignment="Top" Width="6.52" Height="5.383" Fill="#FFAB0404" Stretch="Fill" Data="M8.3585482,7.6118008 C8.3585482,7.6118008 9.3829609,6.4793429 10.484053,5.7423106 13.2862,3.8666516 12.129617,5.3933616 12.129617,5.3933616 L8.6703291,8.0523064 z"/>
                        <Path HorizontalAlignment="Left" Margin="0.287,8.6,0,0" VerticalAlignment="Top" Width="8.35" Height="7.361" Fill="#FFAB0404" Stretch="Fill" Data="M2.9934119,12.280726 C2.9934119,12.280726 5.089625,10.252776 6.167291,9.3225421 7.981912,7.7561752 7.4187557,8.9838185 7.4187557,8.9838185 L2.3691003,12.962527 z"/>
                        <Path HorizontalAlignment="Left" Margin="2.815,1.686,0,0" VerticalAlignment="Top" Width="4.308" Height="6.059" Fill="#FFAB0404" Stretch="Fill" Data="M9.0912287,5.4815006 C9.0912287,5.4815006 8.3470667,4.9998377 8.3478827,3.5762162 8.3480212,3.3346328 10.995948,6.9120685 10.995948,6.9120685 L10.684377,7.2172575 z"/>
                        <Path HorizontalAlignment="Left" Margin="7.841,8.657,0,0" VerticalAlignment="Top" Width="6.912" Height="7.304" Fill="#FFAB0404" Stretch="Fill" Data="M11.86076,8.6826086 C11.86076,8.6826086 10.862828,7.9143165 11.929675,7.7667842 12.168981,7.733691 15.684906,12.169333 15.684906,12.169333 L14.649119,11.36494 z"/>
                    </Grid>
                </ControlTemplate>
            </dg:DataGrid.RowValidationErrorTemplate>

            <dg:DataGrid.Columns>
                <dg:DataGridTemplateColumn>
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <Button Height="20" Width="20" Command="{Binding Source={StaticResource spy}, Path=DataContext.OpenMap}">
                                <Button.Content>
                                    <Image Source="{StaticResource ViewMapIconDark}"/>
                                </Button.Content>
                            </Button>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>
                <dg:DataGridTextColumn x:Name="TitleColumn" 
							Header="Title" Binding="{Binding Title}" 							
							Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowTitle,  							 
		 					    Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />



                <dg:DataGridTextColumn x:Name="PriceColumn" Header="Price" 
					Binding="{Binding Price, StringFormat=\{0:C\}}" 
					Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowPrice, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />
                <dg:DataGridTextColumn x:Name="BedroomsColumn" Header="Bedrooms" Binding="{Binding BedroomCount}" 
                        Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowBedrooms, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />
                <dg:DataGridTextColumn x:Name="BathroomsColumn" Header="Bathrooms" Binding="{Binding BathroomCount}" 
						Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowBathrooms, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />

                <dg:DataGridTemplateColumn x:Name="PhotoColumn" SortMemberPath="HasPhotos" Header=""
						Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowPhotos, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" >
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <!--MAB CHANGE <Image x:Name="HasPhotosIcon" Source="pack://application:,,,/Images/HasPhotosIcon.png" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center" Opacity="{Binding Path=HasPhotos, Converter={StaticResource BoolToOpacityConverter}}" IsHitTestVisible="{Binding Path=HasPhotos}"  ToolTipService.InitialShowDelay="0" Cursor="Hand" >-->
                            <Image x:Name="HasPhotosIcon" Source="pack://application:,,,/Southridge;component/Images/HasPhotosIcon.png" Stretch="None" VerticalAlignment="Center" HorizontalAlignment="Center" Opacity="{Binding Path=HasPhotos, Converter={StaticResource BoolToOpacityConverter}}" IsHitTestVisible="{Binding Path=HasPhotos}"  ToolTipService.InitialShowDelay="0" Cursor="Hand" >
                                <Image.Resources>
                                    <Style TargetType="ToolTip">
                                        <Setter Property="VerticalOffset" Value="-12"   />
                                        <Setter Property="HorizontalOffset" Value="-6"   />
                                        <Setter Property="Placement" Value="Bottom"   />
                                        <Setter Property="Template">
                                            <Setter.Value>
                                                <ControlTemplate TargetType="ToolTip">
                                                    <Grid>
                                                        <controls:CalloutShape ArrowWidth="18" ArrowHeight="12" ArrowOffset="4" RadiusX="0" RadiusY="0" Margin="5">
                                                            <controls:CalloutShape.Effect>
                                                                <DropShadowEffect ShadowDepth="2"  BlurRadius="6" Opacity="1.0" />
                                                            </controls:CalloutShape.Effect>
                                                            <controls:CalloutShape.Fill>
                                                                <LinearGradientBrush StartPoint="0,0" EndPoint="0,1">
                                                                    <GradientStop Color="#FFFFFF" Offset="0" />
                                                                    <GradientStop Color="#E8E8E8" Offset="1" />
                                                                </LinearGradientBrush>
                                                            </controls:CalloutShape.Fill>
                                                        </controls:CalloutShape>
                                                        <ContentPresenter Margin="5,17,5,5" />
                                                    </Grid>
                                                </ControlTemplate>
                                            </Setter.Value>
                                        </Setter>
                                    </Style>
                                </Image.Resources>
                                <Image.ToolTip>
                                    <Image Source="{Binding PrimaryPhoto}" Stretch="Uniform" Width="240" Margin="8" />
                                </Image.ToolTip>
                            </Image>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>
                <dg:DataGridTextColumn x:Name="YearColumn" Header="Year" Binding="{Binding Year}" 
						Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowYear, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />
                <dg:DataGridTextColumn x:Name="SqrFootageColumn" Header="Sqr. Footage" Binding="{Binding SquareFootage}" 
                         Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowSquareFootage, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />

                <dg:DataGridTemplateColumn x:Name="AppointmentColumn" Header="Appointment"
                         Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowAppointment, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" >

                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <dg:DatePicker SelectedDate="{Binding ApptDate, FallbackValue={x:Static sys:DateTime.Today}}" HorizontalContentAlignment="Stretch" Background="White"/>
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>
                <dg:DataGridTemplateColumn x:Name="RatingColumn" SortMemberPath="ClientRating" Header="Rating"						 
                         Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowRating, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" >
                    <dg:DataGridTemplateColumn.CellTemplate>
                        <DataTemplate>
                            <controls:RatingsControl RatingMaximum="5" Rating="{Binding Path=ClientRating, Mode=TwoWay}" />
                        </DataTemplate>
                    </dg:DataGridTemplateColumn.CellTemplate>
                </dg:DataGridTemplateColumn>
                <dg:DataGridTextColumn x:Name="AddressColumn" Header="Address" Binding="{Binding ., Converter={StaticResource ListingToOneLineAddressConverter}}" SortMemberPath="Street" 
						 Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowAddress, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />
                <dg:DataGridTextColumn x:Name="DateListedColumn" Header="Date Listed" Binding="{Binding Path=DatePosted,StringFormat=\{0:MM/dd/yyyy\}}"  
						 Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowDateListed, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />
                <dg:DataGridTextColumn x:Name="DateUpdatedColumn" Header="Date Updated" Binding="{Binding DateLastUpdated,StringFormat=\{0:MM/dd/yyyy\}}" 
						Visibility="{Binding Source={StaticResource spy},Path=DataContext.DataGridColumnsView.ShowDateUpdated, Converter={StaticResource BoolToVisibilityConverter}, Mode=TwoWay}" />
            </dg:DataGrid.Columns>
        </dg:DataGrid>
    </Grid>
</UserControl>
